// 设置 STOMP 客户端
var stompClient = null;
// 设置 WebSocket 进入端点
var SOCKET_ENDPOINT = "/websocket-endpoint";
// 设置订阅消息的请求前缀
var SUBSCRIBE_PREFIX = "/topic"
// 设置订阅消息的请求地址
var SUBSCRIBE = "/";
// 设置服务器端点，访问服务器中哪个接口
var SEND_ENDPOINT = "/app/test";

/* 进行连接 */
function connect() {

    // 设置 SOCKET
    var socket = new SockJS(SOCKET_ENDPOINT);
    // 配置 STOMP 客户端
    stompClient = Stomp.over(socket);
    // STOMP 客户端连接
    stompClient.connect({}, function (frame) {
//         alert("连接成功");
        //alert("connect");
    });
}




function getAllDeviceStatusInfo(){
    // 设置订阅地址
    SUBSCRIBE = SUBSCRIBE_PREFIX + "/allDeviceData" ;
    stompClient.subscribe(SUBSCRIBE, function (responseBody) {
        var receiveMessage = JSON.parse(responseBody.body);
        if(receiveMessage.crane2PLCFlag){
            //未连接时，更改对应的样式
            changePLCText("crane2PLC","已连接","deepskyblue");
            document.getElementById("crane2PLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("crane2PLC","未连接","grey");
            document.getElementById("crane2PLCIMG").style.color = "grey";
        }

        if(receiveMessage.crane4PLCFlag){
            //未连接时，更改对应的样式
            changePLCText("crane4PLC","已连接","deepskyblue");
            document.getElementById("crane4PLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("crane4PLC","未连接","grey");
            document.getElementById("crane4PLCIMG").style.color = "grey";
        }

        if(receiveMessage.craneDJ3PLCFlag){
            //未连接时，更改对应的样式
            changePLCText("craneDJ3PLC","已连接","deepskyblue");
            document.getElementById("craneDJ3PLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("craneDJ3PLC","未连接","grey");
            document.getElementById("craneDJ3PLCIMG").style.color = "grey";
        }


        if(receiveMessage.rollerNo2PLCFlag){
            //未连接时，更改对应的样式
            changePLCText("rollerNo2PLC","已连接","deepskyblue");
            document.getElementById("rollerNo2PLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("rollerNo2PLC","未连接","grey");
            document.getElementById("rollerNo2PLCIMG").style.color = "grey";
        }

        if(receiveMessage.rollerNo45PLCFlag){
            //未连接时，更改对应的样式
            changePLCText("rollerNo45PLC","已连接","deepskyblue");
            document.getElementById("rollerNo45PLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("rollerNo45PLC","未连接","grey");
            document.getElementById("rollerNo45PLCIMG").style.color = "grey";
        }

        if(receiveMessage.operateNo345PLCFlag){
            //未连接时，更改对应的样式
            changePLCText("operateNo345PLC","已连接","deepskyblue");
            document.getElementById("operateNo345PLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("operateNo345PLC","未连接","grey");
            document.getElementById("operateNo345PLCIMG").style.color = "grey";
        }

        if(receiveMessage.crane3PLCFlag){
            //未连接时，更改对应的样式
            changePLCText("crane3PLC","已连接","deepskyblue");
            document.getElementById("crane3PLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("crane3PLC","未连接","grey");
            document.getElementById("crane3PLCIMG").style.color = "grey";
        }


        if(receiveMessage.crane5PLCFlag){
            //未连接时，更改对应的样式
            changePLCText("crane5PLC","已连接","deepskyblue");
            document.getElementById("crane5PLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("crane5PLC","未连接","grey");
            document.getElementById("crane5PLCIMG").style.color = "grey";
        }


        if(receiveMessage.craneDJ2PLCFlag){
            //未连接时，更改对应的样式
            changePLCText("craneDJ2PLC","已连接","deepskyblue");
            document.getElementById("craneDJ2PLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("craneDJ2PLC","未连接","grey");
            document.getElementById("craneDJ2PLCIMG").style.color = "grey";
        }


        if(receiveMessage.rollerNo3PLCFlag){
            //未连接时，更改对应的样式
            changePLCText("rollerNo3PLC","已连接","deepskyblue");
            document.getElementById("rollerNo3PLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("rollerNo3PLC","未连接","grey");
            document.getElementById("rollerNo3PLCIMG").style.color = "grey";
        }

        if(receiveMessage.rollerDJPLCFlag){
            //未连接时，更改对应的样式
            changePLCText("rollerDJPLC","已连接","deepskyblue");
            document.getElementById("rollerDJPLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("rollerDJPLC","未连接","grey");
            document.getElementById("rollerDJPLCIMG").style.color = "grey";
        }


        if(receiveMessage.operateNo2PLCFlag){
            //未连接时，更改对应的样式
            changePLCText("operateNo2PLC","已连接","deepskyblue");
            document.getElementById("operateNo2PLCIMG").style.color = "deepskyblue";
        } else {
            changePLCText("operateNo2PLC","未连接","grey");
            document.getElementById("operateNo2PLCIMG").style.color = "grey";
        }

        if(receiveMessage.upstreamDataSourceFlag){
            //未连接时，更改对应的样式
            changePLCText("upstreamDataSource","已连接","deepskyblue");
            document.getElementById("upstreamDataSourceIMG").style.color = "deepskyblue";
        } else {
            changePLCText("upstreamDataSource","未连接","grey");
            document.getElementById("upstreamDataSourceIMG").style.color = "grey";
        }

        if(receiveMessage.dataSourceFlag){
            //未连接时，更改对应的样式
            changePLCText("dataSource","已连接","deepskyblue");
            document.getElementById("dataSourceIMG").style.color = "deepskyblue";
        } else {
            changePLCText("dataSource","未连接","grey");
            document.getElementById("dataSourceIMG").style.color = "grey";
        }

        if(receiveMessage.dataCollectFlag){
            //未连接时，更改对应的样式
            changePLCText("dataCollect","已连接","deepskyblue");
            document.getElementById("dataCollectIMG").style.color = "deepskyblue";
        } else {
            changePLCText("dataCollect","未连接","grey");
            document.getElementById("dataCollectIMG").style.color = "grey";
        }

    })
}

function changePLCText(textId,text,Textcolor){
     var plc = document.getElementById(textId);
     plc.innerHTML = text ;
     plc.style.color = Textcolor;
}

